﻿Imports lbGlobalcom
Imports Oracle.DataAccess.Client
Public Class fListaPlanes

    Private lIdPlan As String
    Private lValorBase As Decimal
    Private lValorIva As Decimal
    Public ReadOnly Property mValorBase() As Decimal
        Get
            Return lValorBase
        End Get
    End Property

    Public ReadOnly Property mValorIva() As Decimal
        Get
            Return lValorIva
        End Get
    End Property

    Public ReadOnly Property mPlan() As String
        Get
            Return lIdPlan
        End Get
    End Property


    Private Sub btnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancelar.Click
        Me.DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub consultar()
        Dim Conn As OracleConnection = New OracleConnection(My.Settings.ConnectionString)
        Dim cmd As OracleCommand = Conn.CreateCommand
        cmd.CommandText = "SELECT IDPLAN, DESCRIPCION,VALORBASE,VALORIVA FROM PRO_PLANES "
        Dim qWhere As String = ""
        If Me.txtDescripcionPlan.Text.Trim.Length > 0 Then
            qWhere = " WHERE DESCRIPCION LIKE '%" & txtDescripcionPlan.Text & "%'"
        End If
        Try
            Conn.Open()
            cmd.CommandText &= qWhere
            DsProductos.PRO_PLANES.Clear()
            DsProductos.PRO_PLANES.Load(cmd.ExecuteReader)
            Conn.Close()
            PRO_PLANESDataGridView.Focus()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
            lbGlobalcom.cError.SalvaError(ex, "Henry")
        End Try

    End Sub




    Private Sub btnConsultar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConsultar.Click
        Try
            consultar()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Private Sub AsignaMarca(ByVal Fila As Integer)
        If Fila >= 0 Then
            lIdPlan = PRO_PLANESDataGridView.Rows(Fila).Cells("IDPLAN").Value
            lValorBase = PRO_PLANESDataGridView.Rows(Fila).Cells("VALORBASE").Value
            lValorIva = PRO_PLANESDataGridView.Rows(Fila).Cells("VALORIVA").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

    Private Sub PRO_PLANESDataGridView_CellMouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles PRO_PLANESDataGridView.CellMouseDoubleClick
        If e.RowIndex >= 0 Then
            lIdPlan = PRO_PLANESDataGridView.Rows(e.RowIndex).Cells("IDPLAN").Value
            lValorBase = PRO_PLANESDataGridView.Rows(e.RowIndex).Cells("VALORBASE").Value
            lValorIva = PRO_PLANESDataGridView.Rows(e.RowIndex).Cells("VALORIVA").Value
            Me.DialogResult = Windows.Forms.DialogResult.OK
        End If
    End Sub

    Private Sub PRO_PLANESDataGridView_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles PRO_PLANESDataGridView.KeyDown
        If e.KeyData = Keys.Enter Then
            AsignaMarca(PRO_PLANESDataGridView.CurrentRow.Index)
        End If
    End Sub

    Private Sub txtDescripcionPlan_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtDescripcionPlan.KeyDown
        Try
            Select Case e.KeyCode
                Case 13
                    consultar()
            End Select
        Catch ex As Exception
            Throw ex
        End Try
    End Sub
End Class